<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>

</head>

<body class="ms-theme-blue">

  <%@ include file="/WEB-INF/include/header.jsp"%>
  <%@ include file="/WEB-INF/include/submenu.jsp"%>

  <div class="container-fluid ms-container has-ms-sidemenu">

    <ol class="ms-breadcrumb breadcrumb">
      <li class="active">车辆信息管理</li>
    </ol>

    <div class="ms-content-layout">
      
      <div class="alert alert-warning" role="alert">
        <strong>红色车牌号：表示牵引车或挂车审核未通过</strong>
      </div>

      <ul class="nav nav-tabs ms-nav-tabs" role="tablist">
        <li role="presentation" class="${status.unsync ? 'active' : ''}"><a href="${ctx.host}/vehicle-sources?status=UNSYNC">整车编辑</a></li>
        <li role="presentation" class="${status.syncing ? 'active' : ''}"><a href="${ctx.host}/vehicle-sources?status=SYNCING">待引入</a></li>
        <li role="presentation" class="${status.synced ? 'active' : ''}"><a href="${ctx.host}/vehicle-sources?status=SYNCED">已引入</a></li>
        <li role="presentation" class="${status.rejected ? 'active' : ''}"><a href="${ctx.host}/vehicle-sources?status=REJECTED">已驳回</a></li>
      </ul>

      <div class="ms-operation-bar no-margin no-bottom-border clearfix">
        <div class="ms-operation-group">
        
          <div class="pull-right">
            <a href="${ctx.host}/vehicle-sources/search?status=${status}" data-target="#search" data-toggle="modal" class="btn ms-btn ms-btn-blue"> 
              <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
            </a>
            
            <c:if test="${status.unsync and supplier}">
              <a href="${ctx.host}/vehicle-sources/bind" data-target="#bind" data-toggle="modal" class="btn ms-btn ms-btn-blue"> 
                <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;车辆绑定
              </a>
            </c:if>
          </div>
          
        </div>
      </div>

      <table class="table table-hover ms-table">
        <thead>
          <tr>
            <th>序号</th>
            <th>牵引车中文车牌号</th>
            <th>挂车中文车牌号</th>
            <th>运输工具类型</th>
            <th>是否锁定</th>
            <c:if test="${status.rejected}">
              <th class="text-center">驳回理由</th>
            </c:if>
            <c:if test="${status.synced}">
              <th>是否同步TMS</th>
              <th>司机数量</th>
            </c:if>
            <th class="text-center">操作</th>
          </tr>
        </thead>

        <tbody>
          <c:forEach var="vehicleSource" items="${vehicleSources}" varStatus="ordinal">
            
            <c:set var="tractor" value="${persist.tractor(vehicleSource.tractorId)}" />
            <c:set var="trailer" value="${persist.trailer(vehicleSource.trailerId)}" />
          
            <tr>
              <td>${ordinal.count}</td>
              <td class="${tractor.status.qualified ? '' : 'red'}">${vehicleSource.tractorBrandCode}</td>
              <td class="${((not empty trailer) and trailer.status.qualified) ? '' : 'red'}">${vehicleSource.trailerBrandCode}</td>
              <td>${tractor.transMean.description}</td>
              <td>${vehicleSource.lock ? '是' : '否'}</td>
              
              <c:if test="${status.rejected}">
                <td class="text-center">${vehicleSource.rejectReason}</td>
              </c:if>
              
              <c:if test="${status.synced}">
                <td>${vehicleSource.synchronize ? '是' : '否'}</td>
                <td>${persist.getDriverAmount(vehicleSource.code)}</td>
              </c:if>

              <td class="text-center">
              
                <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}?vehicleMenuType=self" data-target="#edit">详情</a>&nbsp;&nbsp; 
                
                <c:choose>
                  <c:when test="${status.unsync}">
                    <c:if test="${(not vam) and (not vehicleSource.vam)}">
                      <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}/change-trailer" data-target="#change-trailer" data-toggle="modal">换挂</a>&nbsp;&nbsp;
                      <c:if test="${not empty trailer}">
    		                <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}/unbind" data-target="#unbind" data-toggle="modal">解绑</a>&nbsp;&nbsp;
                      </c:if>
                    </c:if>
                    
                    <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}/declare" data-target="#declare" data-toggle="modal">引入申报</a>&nbsp;&nbsp;
		              </c:when>
                  
                  <c:when test="${status.syncing}">
                    <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}/cancel-declare" data-target="#cancel-declare" data-toggle="modal">取消引入申报</a>&nbsp;&nbsp;
                  </c:when>
                  
                  <c:when test="${status.synced}">
                    <c:if test="${(not vam) and (not vehicleSource.vam)}">
                      <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}/out" data-target="#out" data-toggle="modal">转出</a>&nbsp;&nbsp;
                      <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}/change-trailer" data-target="#change-trailer" data-toggle="modal">换挂</a>&nbsp;&nbsp;
                      <c:if test="${not empty trailer}">
                        <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}/unbind" data-target="#unbind" data-toggle="modal">解绑</a>&nbsp;&nbsp;
                      </c:if>
                    </c:if>
                  </c:when>
                  
                  <c:when test="${status.rejected}">
                    <c:if test="${(not vam) and (not vehicleSource.vam)}">
                      <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}/change-trailer" data-target="#change-trailer" data-toggle="modal">换挂</a>&nbsp;&nbsp;
                      <c:if test="${not empty trailer}">
                        <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}/unbind" data-target="#unbind" data-toggle="modal">解绑</a>&nbsp;&nbsp;
                      </c:if>
                    </c:if>
                    
                    <a href="${ctx.host}/vehicle-sources/${vehicleSource.id}/declare" data-target="#declare" data-toggle="modal">引入申报</a>&nbsp;&nbsp;
                  </c:when>
                </c:choose>
                
              </td>
            </tr>
          </c:forEach>
        </tbody>

        <tfoot>
          <tr>
            <td colspan="9" class="no-vertical-padding">
              <div class="pull-left">
                <jsp:include page="/WEB-INF/include/page.jsp">
                  <jsp:param name="url" value="vehicle-sources" />
                  <jsp:param name="queryString" value="${queryString}" />
                </jsp:include>
              </div>
            </td>
          </tr>
        </tfoot>
      </table>
    </div>
  </div>

  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource type="script" root="${ctx.resource}/build" src="js/page/supplier/management/vehicle-info-list.js" />
  <script type="text/javascript">
    require(['page/supplier/management/vehicle-info-list'], function (page) {
      page.init()
    })
  </script>

</body>
</html>